import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
	state: {
		userInfo: JSON.parse(uni.getStorageSync('userInfo') || '{}'),
		token: uni.getStorageSync('token') || '',
		location: JSON.parse(uni.getStorageSync('location') || '{}'),
		// 是否初始化 默认未初始化 初始化后设为true
		ceshideta: uni.getStorageSync('ifBindPhone') || false
	},
	mutations: {
		// 保存用户信息
		saveUserInfo(state, userInfo) {
			state.userInfo = userInfo
			uni.setStorageSync('userInfo', JSON.stringify(userInfo))
		},
		// 点击退出登录 清除用户信息 userinfo 为空就显示未登录
		removeUserInfo(state) {
			state.userInfo = {}
			uni.removeStorageSync('userInfo')
		},
		saveToken(state, token) {
			state.token = token
			uni.setStorageSync('token', token)
		},
		removeToken(state) {
			state.token = {}
			uni.removeStorageSync('token')
		},

		ceshi(state, data) {
			state.ceshideta = true
			uni.setStorageSync('ceshideta', true)
		}
	},
	actions: {},
	getters: {

	}
})
export default store